if (!jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.keyMgt.viewEdit.KeystoreUpload")) {
/**
*
*/
    jsx3.Class.defineClass(
            'tibco.admin.enterpriseAssets.keyMgt.viewEdit.KeystoreUpload',
            jsx3.lang.Object,
            null,
            function(upload) {
                upload.form = null;
                upload.noIFrame = false;
                upload.workspace = null;
                upload.prevUploadLocation = null;
                //"http://localhost:8080"+
                upload.servletURL = "/" + tibco.admin.util.ServiceHelper.getAdminWebapp() + "/keystoreupload";
                /**
                 Handle the Browse operation
                 */
                upload.doBrowse = function() {
                    var objText = upload.workspace.getDescendantOfName("txtKeystoreLocation_29B");
                    objText.setEnabled(jsx3.gui.Form.STATEENABLED, true);
                    upload.prevUploadLocation = objText.getValue();
                    if (!upload.form) {
                        upload.initFormNoIFrame();
                    }
                    upload.form.addFileUploadField(objText.getName());
                    upload.form.subscribe(jsx3.net.Form.EVENT_FILE_SELECTED, function(objEvent) {
                        objText.setValue(objEvent.value);
                    });
                    upload.form.promptForFile(objText.getName());
                }

                upload.initialiseBrowser = function(block) {
                    upload.workspace = block;
                    if (document.getElementById && !document.all) {
                        // user is using NS6+ or Firefox
                        upload.noIFrame = false;
                        upload.workspace.getDescendantOfName("blkMozEdit29B").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                        upload.workspace.getDescendantOfName("blkIEEdit29B").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    } else {
                        upload.noIFrame = true;
                        if (!upload.form) {
                            upload.initFormNoIFrame();
                        }
                        upload.workspace.getDescendantOfName("blkMozEdit29B").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                        upload.workspace.getDescendantOfName("blkIEEdit29B").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    }
                }

                upload.initFormNoIFrame = function() {
                    jsx3.require('jsx3.net.Form');
                    upload.form = jsx3.net.Form.newFromFragment('<form id="uploadkeystore" enctype="multipart/form-data"  method="post" action="' + upload.servletURL + '"></form>');
                }

                upload.initIFrame = function() {
                    if (document.getElementById && !document.all) {
                        var internal = upload.workspace?upload.workspace.getDescendantOfName("lblKeystoreType_29B").getText() == tibco.admin.Main.getServer().getDynamicProperty("@lblkeystoreInternal29A"):false;
                        if (internal) {
                            upload.noIFrame = false;
                            var strIFrame = "<iframe id='iFrameMoz29B'  width='250'  height='22' frameborder='no' scrolling='no'></iframe>"
                            upload.workspace.getDescendantOfName('spanMoz29B').setText(strIFrame, true);
                            var strAction = upload.servletURL;
                            var theForm = '<form id="formMoz29B"  enctype="multipart/form-data"  method="post" action="' + strAction + '" ><input id="fileMoz29B" type="file" name="fileLocation" style="position:absolute;top:0;left:0"></input></form>';
                            var docHTML = '<html><head></head><body>' + theForm + '</body></html>';
                            upload._iframe = document.getElementById("iFrameMoz29B");
                            upload._iframe.contentDocument.open();
                            upload._iframe.contentDocument.write(docHTML);
                            setTimeout(function() {
                                upload.form = upload._iframe.contentDocument.getElementById("formMoz29B");
                                upload._iframe.contentDocument.close();
                            }, 100)
                        }
                        else {
                            upload.noIFrame = true;
                            upload.initFormNoIFrame();
                        }
                    }
                };

                upload.initForm = function() {
                    var theForm = '<form id="formMoz29B"  enctype="multipart/form-data"  method="post" action="' + upload.servletURL + '" > ';
                    theForm = theForm + '</form>';
                    var docHTML = '<html><head></head><body>' + theForm + '</body></html>';
                    upload._iframe = document.getElementById("iFrameMoz29B");
                    upload._iframe.contentDocument.open();
                    upload._iframe.contentDocument.write(docHTML);
                    setTimeout(function() {
                        upload.form = upload._iframe.contentDocument.getElementById("formMoz29B");
                        upload._iframe.contentDocument.close();
                    }, 100)
                }

                /**
                 * submit to save the archive file (IE specific)
                 */

                upload.doSubmit = function() {
                    if (!upload.form) {
                        tibco.admin.util.Log.RESOURCES.trace("form is null.");
                        upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@lbl_FormNull_29B"), true);
                        upload.doReset(false);
                        return;
                        // }
                    }

                    upload.workspace.getDescendantOfName('blkMessage29B').setText(tibco.admin.Main.getServer().getDynamicProperty("@@UploadInProgress_29B"), true);
                    if (upload.noIFrame) {
                        upload.form.setField("name", upload.workspace.getDescendantOfName('txtKeystoreName_29B').getValue());
                        upload.form.setField("description", upload.workspace.getDescendantOfName('txtKeystoreDescription_29B').getValue());
                        upload.form.setField("password", upload.workspace.getDescendantOfName('txtKeystorePassword_29B').getValue());

                        if (upload.workspace.getDescendantOfName("lblKeystoreType_29B").getText() == tibco.admin.Main.getServer().getDynamicProperty("@lblkeystoreExternal29A")) {
                            upload.form.setField("url", upload.workspace.getDescendantOfName('txtKeystoreURL_29B').getValue());
                        } else {
                            upload.form.setField("fileLocation", tibco.admin.Main.getServer().getDynamicProperty("@@lbl_Hidden_29B"));
                        }

                        upload.form.subscribe(jsx3.HttpForm.EVENT_ON_RESPONSE, function(objEvent) {
                            tibco.admin.util.Log.RESOURCES.trace("response: \n" + upload.form.getResponseXML())
                            upload.doProfile((new jsx3.xml.Document()).loadXML(upload.form.getResponseXML()));
                            //upload.doReset(true);
                        });
                        upload.form.subscribe(jsx3.HttpForm.EVENT_ON_TIMEOUT, function(objEvent) {
                            tibco.admin.util.Log.RESOURCES.trace("Timeout reached")
                            upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@TimeoutPrefix_29B") + upload.name + tibco.admin.Main.getServer().getDynamicProperty("@@TimeoutSuffix_29B"), true);
                            //Timeout
                            upload.doReset(false);
                        });
                        upload.form.subscribe(jsx3.HttpForm.EVENT_ON_ERROR, function(objEvent) {
                            tibco.admin.util.Log.RESOURCES.trace("Error loading service asembly")
                            upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@ErrorPrefix_29B") + upload.serviceAssemblyName + tibco.admin.Main.getServer().getDynamicProperty("@@ErrorSuffix_29B"), true);
                            //Error
                            upload.doReset(false);
                        });
                        upload.form.setMultipart(true);
                        upload.form.send(500, 60000);

                    }
                    else {
                        upload.doSubmitMZ();
                    }
                }

                upload.doProfile = function(objXML) {
                    try {
                        var successOrFailure = objXML.getRootNode().selectSingleNode("//status").getValue();
                        tibco.admin.util.Log.RESOURCES.trace("Response from file upload [" + successOrFailure + "].")
                        if (successOrFailure != "SUCCESS") {
                            upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@ExistPrefix_29B") + objXML.getRootNode().selectSingleNode("//error"));
                            //exists
                            upload.doReset(false);
                        } else {
                            upload.doReset(true);
                        }

                    }
                    catch(e) {
                        upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@CantUpload_29B"));
                        upload.doReset(false);
                        if (!upload.noIFrame) {
                            upload.initIFrame()
                        }

                    }
                }

                upload.doReset = function(success) {
                    if (upload.noIFrame && upload.form) {
                        upload.form.destroy();
                        upload.initFormNoIFrame();
                    }
                    if (success) {
                        upload.showError("");
                        if (upload.workspace.getDescendantOfName("paneAdd29B").getDisplay() == jsx3.gui.Block.DISPLAYBLOCK)
                            upload.workspace.resetAdd();  //  ...
                        else
                            upload.workspace.resetReload();
                    } else {
                        upload.workspace.getDescendantOfName("txtKeystorePassword_29B").setValue("");

                    }
                    upload.workspace.getDescendantOfName("blkMozEdit29B").repaint();
                    if (upload.noIFrame) {
                        upload.workspace.getDescendantOfName("txtKeystoreLocation_29B").setValue("");
                    }
                    upload.workspace.getDescendantOfName("btnEditKeystore_29B").focus();
                }

                upload.showError = function(msg) {
                    upload.workspace.getDescendantOfName('blkMessage29B').setText(msg, true);
                }

                upload.doSubmitMZ = function() {
                    try {
                        upload.setField("name", upload.workspace.getDescendantOfName('txtKeystoreName_29B').getValue());
                        upload.setField("password", upload.workspace.getDescendantOfName('txtKeystorePassword_29B').getValue());
                        upload.setField("description", upload.workspace.getDescendantOfName('txtKeystoreDescription_29B').getValue());
                        if (upload.workspace.getDescendantOfName("lblKeystoreType_29B").getText() == tibco.admin.Main.getServer().getDynamicProperty("@lblkeystoreExternal29A")) {
                            var urlField = upload.workspace.getDescendantOfName('txtKeystoreURL_29B');
                            upload.setField("url", urlField.getValue());
                        }
                        else {
                            upload.setField("fileLocation", tibco.admin.Main.getServer().getDynamicProperty("@@lbl_Hidden_29B"));
                        }
                        upload.form.encoding = 'multipart/form-data';
                        upload.send();
                    } catch(e) {
                        tibco.admin.util.Log.RESOURCES.error("Problem while sending the keystore. Mozilla-related.", e)
                    }
                }

                upload.setField = function(name, value) {
                    var newInput = document.createElement('input');
                    newInput.setAttribute("type", "hidden");
                    newInput.setAttribute("name", name);
                    newInput.setAttribute("value", value);
                    upload.form.appendChild(newInput);
                }

                upload.send = function(intPollInterval, intTimeout) {
                    if (intPollInterval == null) intPollInterval = 10;
                    if (intTimeout == null) intTimeout = 30000;

                    upload._iframe.onload = function() {
                        upload.onIFrameLoad();
                    }

                    try {
                        upload.form.submit();
                    } catch (e) {
                        tibco.admin.util.Log.RESOURCES.trace("Error loading keystore")
                        upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@ErrorPrefix_29B") + upload.name + tibco.admin.Main.getServer().getDynamicProperty("@@ErrorSuffix_29B"), true);
                        upload.doReset(false);
                        upload.initIFrame()
                        return;
                    }

                    upload._intervalId = window.setTimeout(function() {
                        upload.onIFrameTimeout();
                    }, intPollInterval * intTimeout);
                };

                upload.onIFrameLoad = function() {
                    upload._iframe.onload = null;
                    if (upload._intervalId) {
                        window.clearTimeout(upload._intervalId);
                        upload._intervalId = null;
                    }

                    try {
                        var a = " " + this._iframe.contentDocument.childNodes[0].innerHTML;
                    } catch (e) {
                        jsx3.log("Error loading keystore")
                        upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@ErrorPrefix_29B") + upload.name + tibco.admin.Main.getServer().getDynamicProperty("@@ErrorSuffix_29B"), true);
                        upload.doReset(false);
                        upload.initIFrame()
                        return;
                    }
                    upload.doProfile(upload.getResponseXML());
                    //upload.doReset(true)
                    upload.initIFrame()

                };


                /* @jsxobf-clobber */
                upload.onIFrameTimeout = function() {
                    tibco.admin.util.Log.RESOURCES.trace("Timeout reached")
                    upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@TimeoutPrefix_29B") + upload.name + tibco.admin.Main.getServer().getDynamicProperty("@@TimeoutSuffix_29B"), true);
                    upload.doReset(false)
                    upload.initIFrame()

                };


                upload.getResponseXML = function() {
                    upload._iframe = document.getElementById("iFrameMoz29B");
                    var dcmt = upload._iframe.contentDocument;
                    if (dcmt instanceof XMLDocument) {
                        var x = (new XMLSerializer()).serializeToString(dcmt);
                        return new jsx3.xml.Document().loadXML(x);
                    }
                    else if (dcmt instanceof HTMLDocument) {
                        var x = dcmt.childNodes[0].innerHTML;
                        return new jsx3.xml.Document().loadXML(x);
                    } else {
                        tibco.admin.util.Log.RESOURCES.warn("Unsupported document type: " + dcmt);
                        return new jsx3.xml.Document().loadXML("<html/>");
                    }
                };


            })
}
